package ua.ck.example.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import ua.ck.example.domain.Users;

@Repository
public class UsersDAOImpl implements UsersDAO{
	
	@Autowired
    private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	public List<Users> showUsers() {
		
		return sessionFactory.getCurrentSession().createQuery("from Users")
	            .list();
	}

	
	public void addUsers(Users user) {
		
		sessionFactory.getCurrentSession().save(user);
	}

	
	public void delUsers(Integer id) {
		
		Users user = (Users) sessionFactory.getCurrentSession().load(
                Users.class, id);
        if (null != user) {
            sessionFactory.getCurrentSession().delete(user);
        }
	}

}
